package cn.zhqr.lib.bean;

import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * 权限校验工具集
 * Created by charles on 2018/6/21.
 */
public class UserInfo implements Serializable{
    private Long userid;
    private String nickname;
    private String real_name;//真实姓名
    private String avatar;
    private String token;
    private int init_pwd;//密码是否是初始密码
    private List<String> roles;
    private List<String> perms;
    private int role_level;//最大的角色等级
    private Long unread_msg_count;
    private Integer auth_type;
    private Integer bonus_mode;//分账模式
    private Long agent_id;   //父级id，用户商户modelid=12的员工记录父级商户id

    /**
     * 是否拥有指定的角色中的至少一个
     * @param roles
     * @return
     */
    public boolean hasAnyRole(String... roles){
        if(CollectionUtils.isNotEmpty(this.roles)){
            for(String role : roles){
                if(this.roles.contains(role)){
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 是否拥有指定的所有角色
     * @param roles
     * @return
     */
    public boolean hasAllRole(String... roles){
        if(CollectionUtils.isNotEmpty(this.roles)){
            return this.roles.containsAll(Arrays.asList(roles));
        }
        return false;
    }

    /**
     * 是否拥有指定的权限中的至少一个
     * @param perms
     * @return
     */
    public boolean hasAnyPerm(String... perms){
        if(this.perms.contains("all")){
            return true;
        }
        if(CollectionUtils.isNotEmpty(this.perms)){
            for(String perm : perms){
                if(this.perms.contains(perm)){
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 是否拥有指定的全部权限
     * @param perms
     * @return
     */
    public boolean hasAllPerm(String... perms){
        if(this.perms.contains("all")){
            return true;
        }
        if(CollectionUtils.isNotEmpty(this.perms)){
            return this.perms.containsAll(Arrays.asList(perms));
        }
        return false;
    }

    public Long getUserid() {
        return userid;
    }

    public void setUserid(Long userid) {
        this.userid = userid;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }

    public List<String> getPerms() {
        return perms;
    }

    public void setPerms(List<String> perms) {
        this.perms = perms;
    }

    public int isInit_pwd() {
        return init_pwd;
    }

    public void setInit_pwd(int init_pwd) {
        this.init_pwd = init_pwd;
    }

    public int getRole_level() {
        return role_level;
    }

    public void setRole_level(int role_level) {
        this.role_level = role_level;
    }

    public String getReal_name() {
        return real_name;
    }

    public void setReal_name(String real_name) {
        this.real_name = real_name;
    }

    public Long getUnread_msg_count() {
        return unread_msg_count;
    }

    public void setUnread_msg_count(Long unread_msg_count) {
        this.unread_msg_count = unread_msg_count;
    }

    public Integer getAuth_type() {
        return auth_type;
    }

    public void setAuth_type(Integer auth_type) {
        this.auth_type = auth_type;
    }

    public Integer getBonus_mode() {
        return bonus_mode;
    }

    public void setBonus_mode(Integer bonus_mode) {
        this.bonus_mode = bonus_mode;
    }


    public Long getAgent_id() {
        return agent_id;
    }

    public void setAgent_id(Long agent_id) {
        this.agent_id = agent_id;
    }
}
